<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2022/7/23 0023
 * Time: 17:01
 */

namespace framework\library;


class Request
{

    // 获取http请求方式
    public function getHttpMethod()
    {
        $uri = strtoupper($_SERVER['REQUEST_METHOD']);
        return $uri;
    }

    // 获取URI
    public function getUri()
    {
        $uri = $_SERVER['REQUEST_URI'];
        if (false != $pos = strpos($uri, "?")) {
            $uri = substr($uri, 0, $pos);
        }
        return $uri;
    }

    // 判断是否ajax
    public function isAjax()
    {
        $value  = $_SERVER('HTTP_X_REQUESTED_WITH');
        $result = 'xmlhttprequest' == strtolower($value) ? true : false;

        return $result;
    }

    /**
     * 是否为cli
     * @access public
     * @return bool
     */
    public function isCli()
    {
        return PHP_SAPI == 'cli';
    }

    /**
     * 是否为cgi
     * @access public
     * @return bool
     */
    public function isCgi()
    {
        return strpos(PHP_SAPI, 'cgi') === 0;
    }

}